<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title>添加</title>
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
  <script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.config.js"></script>
  <script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.all.min.js"> </script>
  <script type="text/javascript" charset="utf-8" src="/ueditor/lang/zh-cn/zh-cn.js"> </script>
  <script src="/scripts/jquery.min.js"></script>
  <script src="/scripts/boot.js" type="text/javascript"></script>
  <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
  <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
  <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
  <link rel="stylesheet" href="/editor/common.css">
  <style type="text/css">
    div{
      width:100%;
    }
  </style>
</head>
<body>
<div>
  <div style="padding: 5px">
    <span>标题：</span><input class="mini-textbox" type="text" id="titleOId"  style="width:400px"/>
  </div>
  <div style="padding: 5px;margin-top: 10px">
    <span>内容：</span>
  </div>
  <div id="editor" type="text/plain" style="width:100%;height:500px"></div>
</div>
<div id="btns">
  <div style="margin: 0 auto;text-align: center">
    <a class="mini-button " iconCls="icon-ok" onclick="commit()">确定</a>
    <a class="mini-button" iconCls="icon-cancel" onclick="onCancel">取消</a>
  </div>
</div>
</body>

<script type="text/javascript">
    mini.parse();
    //实例化编辑器
    var ue = UE.getEditor('editor');
    let classifyOId = '<%- classifyOId%>';
    function commit() {
        let title= mini.get("titleOId").getValue();
        let content=UE.getEditor('editor').getContent();


        if(!title||title==""){
            alert("标题不能为空");
            return;
        }
        if(!content||content==""){
            alert("内容不能为空");
            return;
        }
        let imgUrl=getCoverUrl(content);
        if(!imgUrl||imgUrl==""){
            alert("请至少上传一张图片！");
            return;
        }

        var data = {};
        data.classifyOId=classifyOId;
        data.title = title;
        data.content = content;
        console.log(status);
        $.ajax({
            url: "/getdata/addBusinessCollegeSubItem",
            type: 'post',
            data: data,
            cache: false,
            success: function (res) {
                if (res) {
                    alert("添加成功");
                    CloseWindow("close");
                } else {
                    alert("出现错误");
                }

            },

            error: function (error) {
                console.log(error)
            }
        });
    }

    function onCancel() {
        CloseWindow("close");
    }
    function CloseWindow(action) {
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();
    }
    function getCoverUrl(content){
        let m,
            urls = [],
            rex = /<img.*?src="([^">]*\/([^">]*?))".*?>/g;

        while (m = rex.exec(content) ) {
            urls.push( m[1] );
        }
        if(urls&&urls.length>0){
            return  urls[0]
        }else{
            return false
        }
    }
</script>

</html>


